﻿<UserControl x:Class="SubtitleTools.Shell.Preview"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"              
             xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" 
             xmlns:b="clr-namespace:SubtitleTools.Common.Behaviors;assembly=SubtitleTools.Common"
             xmlns:vm="clr-namespace:SubtitleTools.Infrastructure.ViewModels;assembly=SubtitleTools.Infrastructure"
             xmlns:conv="clr-namespace:SubtitleTools.Common.Converters;assembly=SubtitleTools.Common"
             Name="ThisPreview"
             mc:Ignorable="d" 
             d:DesignHeight="700" d:DesignWidth="700">
    <UserControl.Resources>
        <vm:PreviewViewModel x:Key="vmPreviewViewModel" />
        <conv:PlayBtnImageConverter x:Key="convImageConverter" />
        <conv:FileNameConverter x:Key="convFileNameConverter" />
        <conv:TimeSpanConverter x:Key="convTimeSpanConverter" />
    </UserControl.Resources>
    <ScrollViewer   
                HorizontalAlignment="Stretch" 
                VerticalScrollBarVisibility="Visible"   
                HorizontalScrollBarVisibility="Auto"
                VerticalAlignment="Stretch"                                  
                VerticalContentAlignment="Stretch" 
                HorizontalContentAlignment="Stretch" CanContentScroll="True">
        <Grid DataContext="{Binding Source={StaticResource vmPreviewViewModel}}">
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>
            <GroupBox Margin="1" Grid.Row="0" Background="#FF444444"
                      Header="{Binding ElementName=ThisPreview, Path=FilePath, Converter={StaticResource convFileNameConverter}}">
                <Grid Margin="5,5,5,1">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" MinHeight="30"/>
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <MediaElement                         
                            Grid.Row="0" 
                            b:MediaElementBehavior.MediaPath="{Binding ElementName=ThisPreview, Path=FilePath}"
                            b:MediaElementBehavior.PauseMedia="{Binding PreviewModelData.PauseMedia, Mode=TwoWay}"
                            b:MediaElementBehavior.PlayMedia="{Binding PreviewModelData.PlayMedia, Mode=TwoWay}"
                            b:MediaElementBehavior.StopMedia="{Binding PreviewModelData.StopMedia, Mode=TwoWay}"                        
                            b:MediaElementBehavior.NaturalDuration="{Binding PreviewModelData.MediaNaturalDuration, Mode=TwoWay}"
                            b:MediaElementBehavior.MediaError="{Binding PreviewModelData.MediaError, Mode=TwoWay}"
                            b:MediaElementBehavior.MediaPosition="{Binding Path=PreviewModelData.MediaPosition, Mode=TwoWay}"                        
                            b:MediaElementBehavior.MediaManualPosition="{Binding Path=PreviewModelData.MediaManualPosition, Mode=TwoWay}"
                            Margin="5"                         
                            Volume="{Binding Path=PreviewModelData.VolumeSliderValue, Mode=TwoWay}"
                            HorizontalAlignment="Stretch" 
                            VerticalAlignment="Stretch" 
                            Height="Auto"                        
                            Width="Auto"                                               
                            MinHeight="300"
                            MinWidth="400"
                            MaxHeight="450"
                            MaxWidth="600"                            
                            ScrubbingEnabled="True"
                            Source="{Binding ElementName=ThisPreview, Path=FilePath}"
                            LoadedBehavior="Manual"                            
                            Stretch="Fill"/>
                    <Slider 
                        Grid.Row="1"
                        ToolTip="Seek"                      
                        Maximum="{Binding Path=PreviewModelData.SeekBarMaximum, Mode=TwoWay}"
                        SmallChange="1"      
                        b:SliderBehavior.DragCompleted="{Binding Path=PreviewModelData.DragCompleted, Mode=TwoWay}"
                        LargeChange="{Binding Path=PreviewModelData.SeekBarLargeChange, Mode=TwoWay}"
                        Value="{Binding Path=PreviewModelData.SeekBarValue, Mode=TwoWay}"/>
                    <StackPanel 
                        Grid.Row="2"
                        Orientation="Horizontal"  
                        HorizontalAlignment="Center">
                        <Button ToolTip="Play/Pause" 
                                Margin="5" 
                                Command="{Binding DoPlay}" Width="25" Height="25">
                            <Image Width="16" Height="16"
                            Source="{Binding Path=PreviewModelData.PlayImage, Converter={StaticResource convImageConverter}}"  />
                        </Button>

                        <Button ToolTip="Stop" 
                                Margin="5" 
                                Command="{Binding DoStop}" Width="25" Height="25">
                            <Image Source="images/debug-stop-icon.png" Width="16" Height="16" />
                        </Button>

                        <Slider 
                            ToolTip="Volume" 
                            Margin="5"  
                            VerticalAlignment="Center"                             
	                        Minimum="0" 
                            Maximum="1" 
                            Value="{Binding Path=PreviewModelData.VolumeSliderValue, Mode=TwoWay}" 
                            Width="70"/>

                        <TextBox 
                            MinWidth="85"
                            Margin="5"   
                            Text="{Binding Path=PreviewModelData.MediaLen, Mode=TwoWay}" VerticalAlignment="Center" />

                        <TextBlock Foreground="Cyan" 
                                   Margin="5" 
                                   Text="{Binding Path=PreviewModelData.MediaNaturalDuration,Converter={StaticResource convTimeSpanConverter}}" VerticalAlignment="Center" />
                    </StackPanel>
                    <TextBlock 
                        Grid.Row="3"    
                        TextAlignment="Center"
                        FlowDirection="{Binding Path=PreviewModelData.DialogFlowDirection, Mode=TwoWay}"
                        Text="{Binding Path=PreviewModelData.Dialog, Mode=TwoWay}" 
                        Foreground="Yellow" HorizontalAlignment="Center" VerticalAlignment="Center" />
                </Grid>
            </GroupBox>

            <GroupBox Header="Add Subtitle" Grid.Row="1" Margin="1">
                <Grid Margin="5">
                    <Grid.RowDefinitions>
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="Auto" />
                        <RowDefinition Height="*" />
                        <RowDefinition Height="Auto" />
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition Width="Auto" />
                        <ColumnDefinition Width="*" />
                    </Grid.ColumnDefinitions>

                    <Button Grid.Row="0" Grid.Column="0"
                            VerticalAlignment="Center" Content="Start" 
                            Command="{Binding DoPlay}"
                            Margin="5,5,1,5" Width="35" Height="22" />
                    <TextBox Grid.Row="0" Grid.Column="1"
                             Text="{Binding Path=SubtitleItemData.StartTs, Mode=TwoWay, Converter={StaticResource convTimeSpanConverter}}"
                             Width="95" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />

                    <Button Grid.Row="1" Grid.Column="0"
                            Command="{Binding DoPause}"
                            Content="End" Margin="5,5,1,5" VerticalAlignment="Center" Width="35" Height="22" />
                    <TextBox Grid.Row="1" Grid.Column="1"
                             Text="{Binding Path=SubtitleItemData.EndTs, Mode=TwoWay, Converter={StaticResource convTimeSpanConverter}}"
                             Width="95" Margin="5" VerticalAlignment="Center" HorizontalAlignment="Left" />

                    <TextBlock Grid.Row="2" Grid.Column="0"
                               Text="Dialog:" Margin="5,5,1,5" VerticalAlignment="Center" HorizontalAlignment="Center" />
                    <TextBox Grid.Row="2" Grid.Column="1" 
                             TextAlignment="Center"                             
                             b:SetCaretIndexBehavior.CurrentCaretIndex="{Binding Path=SubtitleItemData.CaretIndex, Mode=TwoWay}"
                             FlowDirection="{Binding Path=SubtitleItemData.DialogFlowDirection, Mode=TwoWay}"
                             Text="{Binding Path=SubtitleItemData.Dialog, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                             Width="Auto" Margin="5" VerticalAlignment="Stretch" AcceptsReturn="True" HorizontalAlignment="Stretch" />

                    <StackPanel Grid.Row="3" Grid.Column="1" Orientation="Horizontal" Margin="5">
                        <Button Command="{Binding DoAddSubtitle}"
                                Content="Add"  VerticalAlignment="Center" Width="50" HorizontalAlignment="Left" Height="22" />
                        <Button Command="{Binding DoClearSubtitle}"
                                Content="Clear" VerticalAlignment="Center" Width="50" HorizontalAlignment="Left" Height="22" />
                    </StackPanel>
                </Grid>
            </GroupBox>
        </Grid>
    </ScrollViewer>
</UserControl>
